package com.tchintech.pay.utils;

import android.content.Context;
import android.os.Environment;

import java.io.File;

/**
 * Created by Administrator on 2017/7/13 0013.
 */

public class PathsUtil {
    public static String getAppRoot(){
        StringBuffer sbPath = new StringBuffer();
        sbPath.append("/");
        sbPath.append("Qzhineng");
        sbPath.append("/");
        return sbPath.toString();
    }

    //二维码存放路径
    public static String savecode(String codePath) {
        // 设置ftp的存储磁盘路径 (按照定义规则)
        StringBuffer sbPath = new StringBuffer();
        sbPath.append("/");
        sbPath.append("Qzhineng");
        sbPath.append("/");
        sbPath.append(codePath);
        return sbPath.toString();
    }

    /**
     * Description: 检测sdcard是否存在</p>
     */
    public static boolean checkSdcard() {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 得到保存的根目录
     *
     * @param
     * @return
     */
    public static String getRootPath(Context context) {
        String rootPath = null;
        if (checkSdcard()) {
            rootPath = getSdcardRootPath();
        } else {
            rootPath = getCacheRootPath(context);
        }
        return rootPath;
    }
    /**
     * 获取sdcard目录
     *
     * @return root path
     */
    public static String getSdcardRootPath() {
        File dir = Environment.getExternalStorageDirectory();
        return dir.getAbsolutePath();
    }

    /**
     * 获取内存目录
     *
     * @return root path
     */
    public static String getCacheRootPath(Context context) {
        File cacheDir = context.getCacheDir();
        return cacheDir.getPath();
    }

}
